<%@page import="com.office.automate.model.authenticate.ChangePassword"%>
<%@page import="com.office.automate.service.impl.employee.EmployeeQueryServiceImplementer"%>
<%@page import="com.office.automate.service.def.employee.EmployeeQueryService"%>
<%@page import="com.office.automate.model.administration.Division"%>
<%@page import="com.office.automate.model.administration.Branch"%>
<%@page import="com.office.automate.configuration.property.ConfigurationProperties"%>
<%@page import="java.util.Properties"%>
<%@page import="com.office.automate.model.administration.SecurityLevel"%>
<%@page import="java.util.List"%>
<%@page import="com.office.automate.service.impl.administration.AdministrationServiceImplementer"%>
<%@page import="com.office.automate.service.def.administration.AdministrationService"%>
<%@page import="com.office.automate.frontier.utility.DataConversionUtility"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.office.automate.frontier.utility.ExceptionMessagesManagement"%>
<%@page import="com.office.automate.validation.framework.ValidatorObject"%>
<%@page import="com.office.automate.exception.framework.FrontierVisibleException"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.office.automate.model.employee.Employee"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@ include file="../common/CommonHeaderInfo.jsp"%>
<title>Update Employee</title>
</head>
<body>
	<%@ include file="../common/SiteHeaderSection.jsp" %>
	<%@ include file="../common/MainMenuBar.jsp"%>

		<%
			if (currentUser == null) {
				return;
			}
			Properties configSeqPropspg = ConfigurationProperties.getProps(); 
			Utility utilpg = new Utility(currentUser.getSecurityLevels());
			if (!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("MAIN_ACCOUNT")) ||  
						!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("CHANGE_PASSWORD")))  {
				response.sendRedirect("/OfficeAutomation/jsp/HomePage.jsp");
			}
			boolean isValidationErrorExist = false;
			ExceptionMessagesManagement exceptionMessagesManagement  = null;
			Properties configProps = ConfigurationProperties.getProps();
			DataConversionUtility dataConversionUtility = new DataConversionUtility();
			AdministrationService administrationService = new AdministrationServiceImplementer();
			List<SecurityLevel> availableSecurityLevels = administrationService.getAvailableSecurityLevels();
			List<Branch> availableBranchs = administrationService.getAvailableBranches();
			List<Division> availableDivisions = administrationService.getAvailableDivisions();
			ChangePassword changePassword = (ChangePassword) request.getAttribute("ChangePassword");
			ValidatorObject validationErrors = (ValidatorObject) request.getAttribute("FieldValidationErrors");
			
		%>
		<tr>
		<td>
		<form action="/OfficeAutomation/ChangePasswordServlet" method="post">
		<center>
		<table>
			<tr>
				<td colspan="3"><center><font class="formtablecaption"><u>Change Password</u></font></center><br /></td>
			</tr>
			<tr>
			<%
			if (validationErrors != null) {
				exceptionMessagesManagement = new ExceptionMessagesManagement(validationErrors.getValidationErrorList());
				isValidationErrorExist = true;
			}
			%>
				  <td>
						<table class="mainContentStyles">
							<tr>
								<td>Current Password</td>
								<td><input type="password" name="currentPassword" <% if (isValidationErrorExist) { %> value="<%=changePassword.getCurrentPassword() %>" <% } %>></td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("CurrentPassword")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("CurrentPassword")  %> </font></td>
								</tr>
							<%
							 }
							%>
							<tr>
								<td>New Password</td>
								<td><input type="password" name="newPassword" <% if (isValidationErrorExist) { %> value="<%=changePassword.getNewPassword() %>" <% } %>></td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("NewPassword")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("NewPassword")  %> </font></td>
								</tr>
							<%
							 }
							%>
							<tr>
								<td>Confirm New Password</td>
								<td><input type="password" name="confirmNewPassword" <% if (isValidationErrorExist) { %> value="<%=changePassword.getConfirmNewPassword() %>" <% } %>></td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("ConfirmNewPassword")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("ConfirmNewPassword")  %> </font></td>
								</tr>
							<%
							 }
							%>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="3"><div class="formButtonPanel"><input type="submit" name="submit" value="Submit" /></div></td>
				</tr>
			</table>
		  </center>
		</form>
	  </td>
	</tr>
<%@ include file="../common/SiteFotterSection.jsp" %>
</body>
</html>